<template>
  <div class="app-container">
    <el-form v-model="listQuery" :inline="true">
      <el-form-item label="交易帐号">
        <el-input v-model.trim="listQuery.trade_account_no" clearable style="width: 140px;margin-right: 10px;" />
      </el-form-item>
      <el-form-item label="订单号">
        <el-input v-model.trim="listQuery.order_no" clearable style="width: 260px;margin-right: 10px;" />
      </el-form-item>
      <el-form-item label="订单明细编号">
        <el-input v-model.trim="listQuery.order_detail_no" clearable style="width: 260px;margin-right: 10px;" />
      </el-form-item>
      <el-form-item label="订单类型" required>
        <el-select v-model.number="listQuery.order_type" clearable placeholder="请选择订单类型" style="width: 120px">
          <el-option v-for="(item,key) in orderTypeList" :key="key" :value="item.value" :label="item.name" />
        </el-select>
      </el-form-item>
      <el-form-item label="赎回单类型" required>
        <el-select v-model.number="listQuery.redeem_type" clearable placeholder="请选择赎回单类型" style="width: 120px">
          <el-option v-for="(item,key) in redeemTypeList" :key="key" :label="item.name" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="付款类型">
        <el-select v-model.number="listQuery.pay_type" clearable placeholder="请选择付款类型" style="width: 120px">
          <el-option v-for="(item,key) in payTypeList" :key="key" :value="item.value" :label="item.name" />
        </el-select>
      </el-form-item>
      <el-form-item label="申购状态">
        <el-select v-model.number="listQuery.subscribe_status" clearable placeholder="请选择申购状态" style="width: 120px">
          <el-option v-for="(item,key) in subscribeStatusTypeList" :key="key" :value="item.value" :label="item.name" />
        </el-select>
      </el-form-item>
      <el-form-item label="赎回状态">
        <el-select v-model.number="listQuery.redeem_status" clearable placeholder="请选择赎回状态" style="width: 120px">
          <el-option v-for="(item,key) in redeemStatusTypeList" :key="key" :value="item.value" :label="item.name" />
        </el-select>
      </el-form-item>
      <el-form-item label="对账状态">
        <el-select v-model.number="listQuery.check_status" clearable placeholder="请对账状态" style="width: 120px">
          <el-option v-for="(item,key) in checkStatusList" :key="key" :label="item.name" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="订单时间">
        <el-date-picker
          v-model="input_order_time"
          end-placeholder="结束日期"
          range-separator="至"
          start-placeholder="开始日期"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getList()">查询</el-button>
        <el-button type="primary" @click="openCreateSubscribeDialog">申购</el-button>
        <el-button type="primary" @click="openCreateRedeemDialog">赎回</el-button>

      </el-form-item>
    </el-form>

    <el-table
      v-loading="listLoading"
      :data="list"
      stripe
    >
      <el-table-column label="ID" prop="id" width="60" />
      <el-table-column label="客户姓名" prop="customer_name" />
      <el-table-column label="订单号" prop="order_no" width="220" />
      <el-table-column label="订单类型" prop="order_type">
        <template slot-scope="scope">
          {{ renderType(scope.row.order_type, orderTypeList) }}
        </template>
      </el-table-column>
      <el-table-column label="支付类型" prop="pay_type">
        <template slot-scope="scope">
          {{ renderType(scope.row.pay_type,payTypeList) }}
        </template>
      </el-table-column>
      <el-table-column label="赎回类型" prop="redeem_type">
        <template slot-scope="scope">
          {{ renderType(scope.row.redeem_type,redeemTypeList) }}
        </template>
      </el-table-column>
      <el-table-column label="客户交易账号" prop="trade_account_no" />
      <el-table-column label="总金额" prop="total_amount" />
      <el-table-column label="申购状态" prop="subscribe_status">
        <template slot-scope="scope">
          {{ renderType(scope.row.subscribe_status,subscribeStatusTypeList) }}
        </template>
      </el-table-column>
      <el-table-column label="赎回状态" prop="subscribe_status">
        <template slot-scope="scope">
          {{ renderType(scope.row.redeem_status,redeemStatusTypeList) }}
        </template>
      </el-table-column>
      <el-table-column label="订单时间" prop="order_time" width="180" />
      <el-table-column label="撤单时间" prop="cancel_time" width="180" />
      <el-table-column label="订单余额处理状态" prop="balance_deal_status" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{ renderType(scope.row.balance_deal_status,balanceDealStatusTypeList) }}
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" label="对账状态" prop="check_status">
        <template slot-scope="scope">
          {{ renderType(scope.row.check_status, checkStatusList) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="200px">
        <template slot-scope="scope">
          <el-link :underline="false" type="primary" style="margin-right: 10px;" @click="openOrderDetailDialog(scope.row)">查看明细</el-link>
          <el-tooltip v-if="scope.row.order_type == 1" class="item" effect="dark" content="模拟自动调用汇付付款成功，并向基金公司发起申请" placement="bottom">
            <el-link :underline="false" type="primary" style="margin-right: 10px;" placement="bottom" @click="payOrder(scope.row)">模拟付款</el-link>
          </el-tooltip>
          <el-link :underline="false" type="primary" style="margin-right: 10px;" placement="bottom" @click="confirmTradeFinished(scope.row)">标记订单交易完成</el-link>
          <el-link :underline="false" type="primary" style="margin-right: 10px;" @click="cancelOrder(scope.row)">撤单</el-link>
          <el-link :underline="false" type="primary" style="margin-right: 10px;" @click="orderLogDialog(scope.row)">订单日志</el-link>
          <el-link v-if="scope.row.order_type == 1" :underline="false" type="primary" style="margin-right: 10px;" @click="billListDialog(scope.row)">资金单</el-link>
          <el-tooltip class="item" effect="dark" content="自动将订单设置为交易成功，且对账完成，同时调用公共方法自动处理用户余额">
            <!--            <el-link :underline="false" type="primary" style="margin-right: 10px;" title="" placement="bottom" @click="checkOrder(scope.row)">模拟对账</el-link>-->
          </el-tooltip>
          <el-tooltip
            v-if="scope.row.redeem_status == 5 || scope.row.redeem_status == 4"
            class="item"
            content="存在发起失败的订单明细，允许再次发起申请！"
            effect="dark"
            placement="bottom"
          >
            <el-link
              :underline="false"
              placement="bottom"
              style="margin-right: 10px;"
              type="primary"
              @click="redeemReApply(scope.row)"
            >重新申请
            </el-link>
          </el-tooltip>
          <el-tooltip
            v-if="scope.row.subscribe_status == 5 || scope.row.subscribe_status == 4"
            class="item"
            content="存在发起失败的订单明细，允许再次发起申请！"
            effect="dark"
            placement="bottom"
          >
            <el-link
              :underline="false"
              placement="bottom"
              style="margin-right: 10px;"
              type="primary"
              @click="subscribeReApply(scope.row)"
            >重新申请
            </el-link>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.page_size" @pagination="getList()" />

    <el-dialog title="订单明细" :visible.sync="dialogOrderDetailTableVisible" width="80%">
      <el-table :data="orderDetails">
        <el-table-column property="order_detail_no" label="订单明细编号" />
        <el-table-column property="fund_order_no" label="基金公司订单号" />
        <el-table-column property="fund_trade_account_no" label="基金公司交易账号" />
        <el-table-column property="amount" label="金额" />
        <el-table-column property="fund_code" label="基金代码" />
        <el-table-column label="申购状态" prop="subscribe_detail_status">
          <template slot-scope="scope">
            {{ renderType(scope.row.subscribe_detail_status,subscribeDetailStatusTypeList) }}
          </template>
        </el-table-column>
        <el-table-column label="赎回状态" prop="redeem_detail_status">
          <template slot-scope="scope">
            {{ renderType(scope.row.redeem_detail_status,redeemDetailStatusTypeList) }}
          </template>
        </el-table-column>
        <el-table-column prop="check_status" label="对账状态">
          <template slot-scope="scope">
            {{ renderType(scope.row.check_status,checkStatusTypeList) }}
          </template>
        </el-table-column>
        <el-table-column prop="fund_trade_time" label="基金公司交易完成时间" />
      </el-table>
    </el-dialog>

    <el-dialog
      title="创建申购订单"
      width="600px"
      :visible.sync="subscribeFormShow"
    >
      <el-form :model="subscribeForm" label-position="left" label-width="160px">
        <el-form-item label="客户ID" required>
          <el-select v-model.number="subscribeForm.customer_id" clearable placeholder="请选择客户" style="width: 400px" @change="subscribeSelectCustomer()">
            <el-option
              v-for="(item,key) in customerList"
              :key="key"
              :label="item.id + '：' + item.customer_name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="银行卡" required>
          <el-select v-model.number="subscribeForm.bank_card_id" clearable placeholder="请选择客户" style="width: 400px">
            <el-option
              v-for="(item,key) in bankList"
              :key="key"
              :label="item.bank_card_no + ' ' + item.branch_bank_name"
              :value="item.bank_card_id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="交易方式" required>
          <el-select v-model.number="subscribeForm.trade_way" clearable placeholder="请选择交易方式" style="width: 400px">
            <el-option v-for="(item,key) in subscribeTradeWayList" :key="key" :label="item.name" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="付款类型" required>
          <el-select v-model.number="subscribeForm.pay_type" clearable placeholder="请选择付款类型" style="width: 400px">
            <el-option v-for="(item,key) in payTypeList" :key="key" :label="item.name" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="订单时间" required>
          <el-date-picker
            v-model="subscribeForm.order_time"
            clearable
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            style="width: 400px"
            placeholder="选择订单时间"
          />
        </el-form-item>
        <template v-if="subscribeForm.pay_type === 3">
          <el-form-item label="计划申请时间">
            <el-date-picker
              v-model="subscribeForm.plan_apply_time"
              clearable
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              style="width: 400px"
              placeholder="选择计划申请时间"
            />
          </el-form-item>
          <el-form-item label="对方基金代码">
            <el-input v-model.trim="subscribeForm.other_fund_code" clearable style="width: 120px;margin-right: 10px;" />
          </el-form-item>
          <el-form-item label="对方基金属性">
            <el-select v-model="subscribeForm.other_fund_attribute" clearable placeholder="请选择对方基金属性" style="width: 400px">
              <el-option v-for="(item,key) in fundAttributeList" :key="key" :label="item.name" :value="item.value" />
            </el-select>
          </el-form-item>
        </template>
        <el-form-item label="基金信息" required>
          <template v-for="(item,key) in subscribeForm.fund_info">
            <el-input :key="key" v-model.trim="item.fund_code" clearable style="width: 120px;margin-right: 10px;" />
            <el-input v-model.number="item.amount" clearable style="width: 120px;margin-right: 10px;" />
            <el-button icon="el-icon-delete" @click.prevent="removeSubscribeFundItem(item)" />
          </template>
          <br>
          <el-button icon="el-icon-add" style="margin-top: 10px;" @click.prevent="addSubscribeFundItem()">新增申购基金信息</el-button>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="subscribeFormShow = false">取消</el-button>
        <el-button type="primary" @click="createSubscribeOrder()">创建申购订单</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="创建赎回订单"
      width="600px"
      :visible.sync="redeemFormShow"
    >
      <el-form :model="redeemForm" label-position="left" label-width="160px">
        <el-form-item label="客户ID" required>
          <el-select v-model.number="redeemForm.customer_id" clearable placeholder="请选择客户" style="width: 400px" @change="redeemSelectCustomer()">
            <el-option
              v-for="(item,key) in customerList"
              :key="key"
              :label="item.id + '：' + item.customer_name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="银行卡" required>
          <el-select v-model.number="redeemForm.bank_card_id" clearable placeholder="请选择客户" style="width: 400px">
            <template v-for="item in bankList">
              <el-option v-if="item.trade_account_no" :value="item.bank_card_id" :label="item.bank_card_no + ' ' + item.branch_bank_name" />
            </template>
          </el-select>
        </el-form-item>
        <el-form-item label="赎回类型" required>
          <el-select v-model.number="redeemForm.redeem_type" clearable placeholder="请选择赎回类型" style="width: 400px">
            <el-option v-for="(item,key) in redeemTypeList" :value="item.value" :label="item.name" />
          </el-select>
        </el-form-item>
        <el-form-item label="交易方式" required>
          <el-select v-model.number="redeemForm.trade_way" clearable placeholder="请选择赎回类型" style="width: 400px">
            <el-option v-for="(item,key) in redeemTradeWayList" :value="item.value" :label="item.name" />
          </el-select>
        </el-form-item>
        <template v-if="redeemForm.trade_way === 3">
          <el-form-item label="对方基金代码">
            <el-input v-model.trim="redeemForm.other_fund_code" clearable style="width: 120px;margin-right: 10px;" />
          </el-form-item>
          <el-form-item label="对方基金属性">
            <el-select v-model="redeemForm.other_fund_attribute" clearable placeholder="请选择对方基金属性" style="width: 400px">
              <el-option v-for="(item,key) in fundAttributeList" :key="key" :label="item.name" :value="item.value" />
            </el-select>
          </el-form-item>
        </template>
        <el-form-item label="订单时间" required>
          <el-date-picker
            v-model="redeemForm.order_time"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            style="width: 400px"
            clearable
            placeholder="选择订单时间"
          />
        </el-form-item>

        <el-form-item label="基金信息" required>
          <template v-for="(item,key) in redeemForm.fund_info">
            <el-input :key="key" v-model.trim="item.fund_code" clearable style="width: 120px;margin-right: 10px;" />
            <el-input v-model.number="item.amount" clearable style="width: 120px;margin-right: 10px;" />
            <el-button icon="el-icon-delete" @click.prevent="removeRedeemFundItem(item)" />
          </template>
          <br>
          <el-button icon="el-icon-add" style="margin-top: 10px;" @click.prevent="addRedeemFundItem()">新增赎回基金信息</el-button>
        </el-form-item>

      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="redeemFormShow = false">取消</el-button>
        <el-button type="primary" @click="createRedeemOrder()">创建赎回订单</el-button>
      </div>
    </el-dialog>

    <el-dialog title="订单日志" :visible.sync="orderLogDialogShow" width="70%">
      <el-table :data="orderLogList">
        <el-table-column property="id" label="日志ID" width="80" />
        <el-table-column property="log_type" label="日志类型">
          <template slot-scope="scope">
            {{ renderType(scope.row.log_type, orderLogTypeList) }}
          </template>
        </el-table-column>
        <el-table-column property="createtime" label="创建时间" />
        <el-table-column property="order_detail_no" label="订单明细编号" />
        <el-table-column property="content" label="日志内容" />
      </el-table>
    </el-dialog>

    <el-dialog title="资金单" :visible.sync="billListShow" width="70%">
      <el-table :data="billList">
        <el-table-column property="id" label="日志ID" />
        <el-table-column property="bill_type" label="资金单类型">
          <template slot-scope="scope">
            {{ renderType(scope.row.bill_type, billTypeList) }}
          </template>
        </el-table-column>
        <el-table-column property="amount" label="金额" />
        <el-table-column property="source" label="入账来源">
          <template slot-scope="scope">
            {{ renderType(scope.row.source, sourceTypeList) }}
          </template>
        </el-table-column>
        <el-table-column property="serial_no" label="流水号" />
        <el-table-column property="trade_time" label="交易时间" />
        <el-table-column property="order_no" label="订单编号" />
        <el-table-column property="order_detail_no" label="订单明细编号" />
        <el-table-column property="memo" label="备注" />
      </el-table>
    </el-dialog>

  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import {
  cancelOrder,
  checkOrder,
  createRedeemOrder,
  createSubscribeOrder,
  orderBillList,
  orderDetail,
  orderList,
  orderLogList,
  payOrder,
  redeemReApply,
  subscribeReApply,
  confirmTradeFinished
} from '@/api/order'
import { Message } from 'element-ui'
import { bankCardList, customerList } from '@/api/customer'
import { getDateTime } from '@/utils'

export default {
  name: 'OrderList',
  components: { Pagination },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        keyword: '',
        state: null,
        page: 1,
        page_size: 10,
        pay_type: null,
        order_type: null,
        trade_account_no: null,
        subscribe_status: null,
        redeem_status: null,
        order_no: null,
        order_detail_no: null,
        redeem_type: null,
        order_time_start: null,
        order_time_end: null
      },
      orderDetails: [],
      dialogOrderDetailTableVisible: false,
      subscribeFormShow: false,
      customerList: [], // 客户列表
      bankList: [], // 银行卡列表
      defaultFundCode: '011754',
      subscribeForm: {
        customer_id: null,
        bank_card_id: null,
        order_time: '',
        pay_type: 1,
        fund_info: [],
        trade_way: 1, // 交易方式：1-充值；2-提现；3-购买基金（提现）；4-基金退款（充值）
        plan_apply_time: null, // 计划申请时间
        other_fund_code: null, // //对方基金代码，转购时必填的交易基金代码
        other_fund_attribute: null// 对方基金属性：1-公募；2-私募
      },
      redeemFormShow: false,
      redeemForm: {
        customer_id: null,
        trade_account_no: '',
        order_time: '',
        redeem_type: 11,
        fund_info: [],
        trade_way: 2, // 交易方式：2-提现；3-购买基金（提现）
        other_fund_code: null, // //对方基金代码，转购时必填的交易基金代码
        other_fund_attribute: null// 对方基金属性：1-公募；2-私募
      },
      payTypeList: [
        {
          name: '汇付',
          value: 1
        },
        {
          name: '线下打款',
          value: 2
        },
        {
          name: '转账交易（赎回转购）',
          value: 3
        }
      ],
      fundAttributeList: [
        {
          name: '公募',
          value: '1'
        },
        {
          name: '私募',
          value: '2'
        }
      ],
      subscribeTradeWayList: [
        {
          name: '充值',
          value: 1
        },
        {
          name: '基金退款（充值）',
          value: 4
        }
      ],
      redeemTradeWayList: [
        {
          name: '提现',
          value: 2
        },
        {
          name: '购买基金（提现）',
          value: 3
        }
      ],
      redeemTypeList: [
        {
          name: '普通赎回',
          value: 11
        },
        {
          name: '快速赎回',
          value: 10
        }
      ],
      orderTypeList: [
        {
          name: '申购单',
          value: 1
        },
        {
          name: '赎回单',
          value: 2
        }
      ],
      subscribeStatusTypeList: [
        // 充值订单状态：-2-已失效；-1-已撤单；0-待支付；1-已支付；2-申请成功；3-交易成功；4-交易失败；5-交易异常；',
        { name: '已失效', value: -2 },
        { name: '已撤单', value: -1 },
        { name: '待支付', value: 0 },
        { name: '已支付', value: 1 },
        { name: '申请成功', value: 2 },
        { name: '交易成功', value: 3 },
        { name: '交易失败', value: 4 },
        { name: '交易异常', value: 5 }
      ],
      redeemStatusTypeList: [
        // 取现订单状态：-1-已撤单；1-待申请；2-申请成功；3-交易成功；4-交易失败；5-交易异常；'
        { name: '已撤单', value: -1 },
        { name: '已支付', value: 1 },
        { name: '申请成功', value: 2 },
        { name: '交易成功', value: 3 },
        { name: '交易失败', value: 4 },
        { name: '交易异常', value: 5 }
      ],
      subscribeDetailStatusTypeList: [
        // '充值订单状态：-1-已撤单；1-待申请；2-申请成功；3-交易成功；4-交易失败；',
        { name: '已撤单', value: -1 },
        { name: '待申请', value: 1 },
        { name: '申请成功', value: 2 },
        { name: '交易成功', value: 3 },
        { name: '交易失败', value: 4 }
      ],
      redeemDetailStatusTypeList: [
        // '取现订单状态：-1-已撤单；1-待申请；2-申请成功；3-交易成功；4-交易失败；',
        { name: '已撤单', value: -1 },
        { name: '待申请', value: 1 },
        { name: '申请成功', value: 2 },
        { name: '交易成功', value: 3 },
        { name: '交易失败', value: 4 }
      ],
      checkStatusTypeList: [
        // 对账状态，0未对账，1成功，2异常
        { name: '待对账', value: 0 },
        { name: '成功', value: 1 },
        { name: '异常', value: 2 }
      ],
      // 订单余额处理状态：0-待处理；1-申请成功余额处理完成；2-交易成功余额处理完成
      balanceDealStatusTypeList: [
        // 对账状态，0未对账，1成功，2异常
        { name: '待处理', value: 0 },
        { name: '申请成功余额处理完成', value: 1 },
        { name: '交易成功余额处理完成', value: 2 }
      ],
      orderLogDialogShow: false,
      orderLogList: [],
      billListShow: false,
      billList: [],
      billTypeList: [
        { name: '转入', value: 1 },
        { name: '转出', value: 2 }
      ],
      sourceTypeList: [
        { name: '汇付', value: 1 },
        { name: '线下打款', value: 2 }
      ],
      orderLogTypeList: [
        { name: '用户行为', value: 1 },
        { name: '系统行为', value: 2 }
      ],
      input_order_time: [],
      checkStatusList: [
        { name: '未对账', value: 0 },
        { name: '成功', value: 1 },
        { name: '异常', value: 2 }
      ]
    }
  },
  created() {
    this.getList()
    this.getCustomerList()
  },
  methods: {
    getList() {
      this.listLoading = true

      if (this.input_order_time.length >= 2) {
        this.listQuery.order_time_start = this.input_order_time[0]
        this.listQuery.order_time_end = this.input_order_time[1]
      }

      orderList(this.listQuery).then(res => {
        this.list = res.list
        this.total = res.pager.total
        this.listQuery.page = res.pager.page
        this.listQuery.page_size = res.pager.page_size
      }).catch((res) => {})
      this.listLoading = false
    },
    getCustomerList() {
      const params = {
        page: 1,
        page_size: 1000
      }
      customerList(params).then(res => {
        this.customerList = res.list
      }).catch(err => {})
    },
    openOrderDetailDialog(row) {
      console.log(row)
      if (!row || !row.customer_id) {
        Message({
          message: '信息异常',
          type: 'error',
          duration: 5 * 1000
        })
        return
      }
      orderDetail({ order_no: row.order_no, customer_id: row.customer_id }).then(res => {
        this.orderDetails = res.details
        this.dialogOrderDetailTableVisible = true
      }).catch((res) => {})
    },
    openCreateSubscribeDialog() {
      this.subscribeFormShow = true
      this.subscribeForm.order_time = getDateTime()
      this.subscribeForm.fund_info = []
      this.subscribeForm.other_fund_attribute = null
      this.subscribeForm.other_fund_code = null
      this.subscribeForm.plan_apply_time = null
      this.addSubscribeFundItem()
    },
    createSubscribeOrder() {
      if (this.subscribeForm.pay_type !== 3) {
        this.subscribeForm.plan_apply_time = null
        this.subscribeForm.other_fund_code = null
        this.subscribeForm.other_fund_attribute = null
      }
      createSubscribeOrder(this.subscribeForm).then(res => {
        this.getList()
        Message.success('操作成功')
        this.subscribeFormShow = false
      }).catch(res => {})
    },
    subscribeSelectCustomer() {
      bankCardList({
        customer_id: this.subscribeForm.customer_id,
        page: 1,
        page_size: 100
      }).then(res => {
        this.bankList = res.list
      }).catch(res => {})
    },

    openCreateRedeemDialog() {
      this.redeemFormShow = true
      this.redeemForm.order_time = getDateTime()
      this.redeemForm.fund_info = []
      this.redeemForm.other_fund_attribute = null
      this.redeemForm.other_fund_code = null
      this.redeemForm.plan_apply_time = null
      this.addRedeemFundItem()
    },
    createRedeemOrder() {
      // 发起赎回
      if (this.redeemForm.trade_way !== 3) {
        this.redeemForm.other_fund_code = null
        this.redeemForm.other_fund_attribute = null
      }
      createRedeemOrder(this.redeemForm).then(res => {
        this.getList()
        Message.success('操作成功')
        this.redeemFormShow = false
      }).catch(res => {})
    },
    redeemSelectCustomer() {
      bankCardList({
        customer_id: this.redeemForm.customer_id,
        page: 1,
        page_size: 100
      }).then(res => {
        this.bankList = res.list
      }).catch(res => {})
    },
    renderType(type, list) {
      if (!list) {
        return type
      }
      let name = ''
      list.forEach(function(ele) {
        if (ele.value === type) {
          return name = ele.name
        }
      })
      return name + '[' + type + ']'
    },
    payOrder(row) {
      payOrder({
        customer_id: row.customer_id,
        order_no: row.order_no
      }).then(res => {
        this.getList()
        Message.success('操作成功')
      }).catch(res => {})
    },
    confirmTradeFinished(row) {
      confirmTradeFinished({
        order_no: row.order_no
      }).then(res => {
        this.getList()
        Message.success('操作成功')
      }).catch(res => {})
    },
    cancelOrder(row) {
      cancelOrder({
        customer_id: row.customer_id,
        order_no: row.order_no,
        cancel_time: getDateTime()
      }).then(res => {
        this.getList()
        Message.success('操作成功')
      }).catch(res => {})
    },
    orderLogDialog(row) {
      orderLogList({
        order_no: row.order_no,
        page: 1,
        page_size: 100
      }).then(res => {
        this.orderLogList = res.list
        this.orderLogDialogShow = true
      }).catch(res => {})
    },
    billListDialog(row) {
      orderBillList({
        order_no: row.order_no,
        page: 1,
        page_size: 100
      }).then(res => {
        this.billList = res.list
        this.billListShow = true
      }).catch(res => {})
    },
    removeSubscribeFundItem(item) {
      var index = this.subscribeForm.fund_info.indexOf(item)
      if (index !== -1) {
        this.subscribeForm.fund_info.splice(index, 1)
      }
    },
    addSubscribeFundItem() {
      this.subscribeForm.fund_info.push({
        fund_code: this.defaultFundCode,
        amount: null
      })
    },
    removeRedeemFundItem(item) {
      var index = this.redeemForm.fund_info.indexOf(item)
      if (index !== -1) {
        this.redeemForm.fund_info.splice(index, 1)
      }
    },
    addRedeemFundItem() {
      this.redeemForm.fund_info.push({
        fund_code: this.defaultFundCode,
        amount: null
      })
    },
    checkOrder(row) {
      checkOrder({
        order_no: row.order_no
      }).then(res => {
        this.getList()
        Message.success('操作成功')
      }).catch(res => {})
    },
    redeemReApply(row) {
      redeemReApply({
        order_no: row.order_no
      }).then(res => {
        this.getList()
        Message.success('操作成功')
      }).catch(res => {
      })
    },
    subscribeReApply(row) {
      subscribeReApply({
        order_no: row.order_no
      }).then(res => {
        this.getList()
        Message.success('操作成功')
      }).catch(res => {
      })
    }
  }
}
</script>

<style scoped>

</style>
